/*Game.java*/
import java.awt.*;
import javax.swing.*;

public class Game {
public JMenuBar createMenuBar() {

JMenuBar menuBar = new JMenuBar();

menuBar.setLayout(new BoxLayout(menuBar, BoxLayout.Y_AXIS));

menuBar.add(createMenu("BUY"));
menuBar.add(createMenu("SELL"));

menuBar.setBorder(BorderFactory.createMatteBorder(0,0,0,3,Color.BLACK));
return menuBar;
}

public JMenuBar createPanelMenuBar() {

JMenuBar panelMenuBar = new JMenuBar();
panelMenuBar.setLayout(new BoxLayout(panelMenuBar, BoxLayout.X_AXIS));

/*First Sub-Panel*/
JPanel subPanel1 = new JPanel();
subPanel1.setPreferredSize(new Dimension(150, 500));
subPanel1.setBorder(BorderFactory.createTitledBorder("STOCK"));

JLabel myLabel = new JLabel("<html><br>APPLE<br><br><br><br><br><br><br>SONY" +
" <br><br><br><br><br><br><br>MICROSOFT" +
" <br><br><br><br><br><br><br>WALMART<br><br><br><br><br><br><br>IBM" +
" <br><br><br><br><br><br><br>AMD<br><br><br><br><br><br><br>INTEL</html>");

subPanel1.setBounds(100, 25, 100, 700);// Direction and Height/Width
panelMenuBar.add (subPanel1);

subPanel1.add(myLabel);

/*Second Sub-Panel*/
JPanel subPanel2 = new JPanel();
subPanel2.setPreferredSize(new Dimension(150, 500));
subPanel2.setBorder(BorderFactory.createTitledBorder("SHARES"));
subPanel2.setBounds(200, 25, 100, 700);// Direction and Height/Width
panelMenuBar.add (subPanel2);

/*Third Sub-Panel*/
JPanel subPanel3 = new JPanel();
subPanel3.setPreferredSize(new Dimension(150, 500));
subPanel3.setBorder(BorderFactory.createTitledBorder("PRICE"));
subPanel3.setBounds(300, 25, 100, 700);// Direction and Height/Width
panelMenuBar.add (subPanel3);

/*Fourth Sub-Panel*/
JPanel subPanel4 = new JPanel();
subPanel4.setPreferredSize(new Dimension(150, 500));
subPanel4.setBorder(BorderFactory.createTitledBorder("TODAY"));
subPanel4.setBounds(400, 25, 100, 700);// Direction and Height/Width
panelMenuBar.add (subPanel4);

/*Fifth Sub-Panel*/
JPanel subPanel5 = new JPanel();
subPanel5.setPreferredSize(new Dimension(150, 500));
subPanel5.setBorder(BorderFactory.createTitledBorder("OVERALL"));
subPanel5.setBounds(500, 25, 100, 700);// Direction and Height/Width
panelMenuBar.add (subPanel5);

panelMenuBar.setBorder(BorderFactory.createMatteBorder(0,0,0,3,Color.BLACK));
return panelMenuBar;
}

public JMenuBar createCashLabelMenuBar() {

JMenuBar cashLabelMenuBar = new JMenuBar();
cashLabelMenuBar.setLayout(new BoxLayout(cashLabelMenuBar, BoxLayout.Y_AXIS));

/*Sixth Sub-Panel*/
JPanel subPanel6 = new JPanel();
subPanel6.setPreferredSize(new Dimension(125, 25));
JLabel label6 = new JLabel ("CASH: "); // cash.
subPanel6.setBounds(700, 25, 100, 25);// Direction and Height/Width
label6.setForeground(Color.red);//Set Text Color
cashLabelMenuBar.add (label6);

cashLabelMenuBar.setBorder(BorderFactory.createMatteBorder(0,0,0,3,Color.BLACK));
return cashLabelMenuBar;

}

public JMenuBar createNetWorthLabelMenuBar() {

JMenuBar netWorthLabelsMenuBar = new JMenuBar();
netWorthLabelsMenuBar.setLayout(new BoxLayout(netWorthLabelsMenuBar, BoxLayout.Y_AXIS));

/*Seventh Sub-Panel*/
JPanel subPanel7 = new JPanel();
subPanel7.setPreferredSize(new Dimension(200, 50));
JLabel label7 = new JLabel ("NET-WORTH: ");// net-worth.
subPanel7.setBounds(850, 25, 100, 25);// Direction and Height/Width
label7.setForeground(Color.blue);
netWorthLabelsMenuBar.add (label7);

netWorthLabelsMenuBar.setBorder(BorderFactory.createMatteBorder(0,0,0,3,Color.BLACK));
return netWorthLabelsMenuBar;

}

// used by createMenuBar.
public JMenu createMenu(String title) {
JMenu m = new HorizontalMenu(title);
m.add("APPLE");
m.add("SONY");
m.add("MICROSOFT");
m.add("WALLMART");
m.add("IBM");
m.add("AMD");
m.add("INTEL");

return m;
}

/**
* Create the GUI and show it.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
JFrame frame = new JFrame("STOCK SIM");
frame.setLocation(300, 25);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
Game demo = new Game();
Container contentPane = frame.getContentPane();
contentPane.setBackground(Color.WHITE); //contrasting bg

contentPane.add(demo.createMenuBar(),
BorderLayout.LINE_START);

contentPane.add(demo.createPanelMenuBar(),
BorderLayout.CENTER);

contentPane.add(demo.createCashLabelMenuBar(),
BorderLayout.PAGE_START);

contentPane.add(demo.createNetWorthLabelMenuBar(),
BorderLayout.PAGE_END);

//Display the window.
frame.setSize(1024, 768);
frame.setVisible(true);
}

public static void initialize(int xRes, int yRes) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
createAndShowGUI();
}

class HorizontalMenu extends JMenu {
HorizontalMenu(String label) {
super(label);
JPopupMenu pm = getPopupMenu();
pm.setLayout(new BoxLayout(pm, BoxLayout.LINE_AXIS));
}

public Dimension getMinimumSize() {
return getPreferredSize();
}

public Dimension getMaximumSize() {
return getPreferredSize();
}

public void setPopupMenuVisible(boolean b) {
boolean isVisible = isPopupMenuVisible();
if (b != isVisible) {
if ((b==true) && isShowing()) {
//Set location of popupMenu (pulldown or pullright).
//Perhaps this should be dictated by L&F.
int x = 0;
int y = 0;
Container parent = getParent();
if (parent instanceof JPopupMenu) {
x = 0;
y = getHeight();
} else {
x = getWidth();
y = 0;
}
getPopupMenu().show(this, x, y);
} else {
getPopupMenu().setVisible(false);
}
}
}
}
}
